package com.example.springboot.flowable;

/**
 * @author yuwl
 * @description
 * @since 2024-08-08 18:29
 */

import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.repository.Deployment;
import org.flowable.engine.runtime.ProcessInstance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProcessController {

    @Autowired
    private RuntimeService runtimeService;

    @Autowired
    private RepositoryService repositoryService;

    @GetMapping("/start-process")
    public String startProcess() {
        Deployment deploy = repositoryService.createDeployment()
                .addClasspathResource("processes/dynamic-task-assignment.bpmn20.xml")
                .name("动态任务分配")
                .category("动态任务")
                .tenantId("test0808")
                .deploy();

        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("dynamicTaskAssignmentProcess");
        return "Process instance ID: " + processInstance.getId();
    }
}

